<?php

	class IndexModel extends Model{

		public function IndexAction(){
			var_dump($this->link);
		}
		public function loginAction(){
			$user = isset($_POST['user']) ? $_POST['user'] : null;
			$pwd = isset($_POST['pwd']) ? $_POST['pwd'] : null;
			$yzm = isset($_POST['yzm']) ? $_POST['yzm'] : null;
			if($yzm != $_SESSION['veri']){
				echo json_encode(['code'=>201,'msg'=>'验证码错误']);
				return;
			}else{
				$sql = "select * from admin where username = '{$user}' and pwd = '{$pwd}'";

				$str = $this->link->selectRows($sql);

				if($str){
					$_SESSION['admin'] = $str;
					echo json_encode(['code'=>200,'msg'=>'登录成功']);
				}else{
					echo json_encode(['code'=>202,'msg'=>'登陆失败','sql'=>$sql]);
				}
			}

		}

		public function isLoginAction(){
		    $admin = isset($_SESSION['admin'])  ? $_SESSION['admin'] : null;
			if($admin){
				echo json_encode(['code'=>200,'msg'=>'true']);
			}else{
				echo json_encode(['code'=>201,'msg'=>'false']);
			}
		}

		public function exitLoginAction(){
		    unset($_SESSION['admin']);
		    echo json_encode(true);

        }


	}